<?php

namespace App\Http\Controllers\Api;

use App\Model\Goods;
use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class GoodsController extends Controller
{
    public function detail(Request $request){
        $id = $request->input("goodsId");
        $goods = new Goods();
        $goodsInfo = $goods->find($id);
        $goodsInfo['comments'] = $goods->leftJoin('comment','goods.id','=','goods_id')->leftJoin('user','comment.user_id','=','user.id')->where('goods.id','=',$id)->where('comment.status','=','1')->orderBy('comment.created_at','desc')->get();
        if(!empty($goodsInfo)){
            $this->success($goodsInfo);
        }else{
            $this->error('商品不存在'.__LINE__);
        }
    }
}
